// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   contact_check_ok.java

package draft.crm;

import include.auto_execute.ContactExpiry;
import include.nseer_cookie.GetWorkflow;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataTag;

public class contact_check_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;
	nseer_db_backup1 erp_db;

	public contact_check_ok()
	{
		erp_db = null;
	}

	public synchronized void doPost(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			nseer_db_backup1 crm_db = new nseer_db_backup1(dbApplication);
			ContactExpiry contactExpiry = new ContactExpiry();
			ValidataTag vt = new ValidataTag();
			if (crm_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String contact_ID = request.getParameter("contact_ID");
				String reason = request.getParameter("reason");
				String reasonexact = request.getParameter("reasonexact");
				String customer_ID = request.getParameter("customer_ID");
				String customer_name = request.getParameter("customer_name");
				String person_contacted = request.getParameter("person_contacted");
				String person_contacted_tel = request.getParameter("person_contacted_tel");
				String contact_person = request.getParameter("contact_person");
				String contact_person_ID = request.getParameter("contact_person_ID");
				String contact_time = request.getParameter("contact_time");
				String contact_type = request.getParameter("contact_type");
				String checker = request.getParameter("checker");
				String contact_content = new String(request.getParameter("contact_content").getBytes("UTF-8"), "UTF-8");
				if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "crm_contact", "contact_ID", contact_ID, "check_tag").equals("5") || vt.validata((String)dbSession.getAttribute("unit_db_name"), "crm_contact", "contact_ID", contact_ID, "check_tag").equals("9"))
				{
					try
					{
						String sql = (new StringBuilder("update crm_contact set contact_ID='")).append(contact_ID).append("',reason='").append(reason).append("',reasonexact='").append(reasonexact).append("',customer_ID='").append(customer_ID).append("',customer_name='").append(customer_name).append("',person_contacted='").append(person_contacted).append("',person_contacted_tel='").append(person_contacted_tel).append("',contact_person='").append(contact_person).append("',contact_person_ID='").append(contact_person_ID).append("',contact_time='").append(contact_time).append("',contact_type='").append(contact_type).append("',contact_content='").append(contact_content).append("',checker='").append(checker).append("' where contact_ID='").append(contact_ID).append("'").toString();
						crm_db.executeUpdate(sql);
						List rsList = GetWorkflow.getList(crm_db, "crm_config_workflow", "03");
						String elem[] = new String[3];
						if (rsList.size() == 0)
						{
							sql = (new StringBuilder("update crm_contact set check_tag='1' where contact_ID='")).append(contact_ID).append("'").toString();
							crm_db.executeUpdate(sql);
							int contact_amount = 0;
							String sql3 = (new StringBuilder("select contact_amount from crm_file where customer_ID='")).append(customer_ID).append("'").toString();
							ResultSet rs3 = crm_db.executeQuery(sql3);
							if (rs3.next())
								contact_amount = rs3.getInt("contact_amount") + 1;
							String sql4 = (new StringBuilder("update crm_file set contact_amount='")).append(contact_amount).append("',lately_contact_time='").append(contact_time).append("',remind_contact_tag='0' where customer_ID='").append(customer_ID).append("'").toString();
							crm_db.executeUpdate(sql4);
							contactExpiry.flow(dbApplication);
						} else
						{
							sql = (new StringBuilder("update crm_contact set check_tag='0' where contact_ID='")).append(contact_ID).append("'").toString();
							crm_db.executeUpdate(sql);
							for (Iterator ite = rsList.iterator(); ite.hasNext(); crm_db.executeUpdate(sql))
							{
								elem = (String[])ite.next();
								sql = (new StringBuilder("insert into crm_workflow(config_id,object_ID,describe1,describe2) values ('")).append(elem[0]).append("','").append(contact_ID).append("','").append(elem[1]).append("','").append(elem[2]).append("')").toString();
							}

						}
					}
					catch (Exception ex)
					{
						ex.printStackTrace();
					}
					response.sendRedirect("draft/crm/contact_ok.jsp?finished_tag=1");
				} else
				{
					response.sendRedirect("draft/crm/contact_ok.jsp?finished_tag=5");
				}
				crm_db.commit();
				crm_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
